package cn.com.sd.system.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.com.sd.common.util.MyStringUtils;
import cn.com.sd.common.util.Page;
import cn.com.sd.system.dao.IPrivilegeDAO;
import cn.com.sd.system.model.Privilege;

@SuppressWarnings("unchecked")
@Component(value = "privilegeDAO")
public class PrivilegeDAOHibernate extends BaseDAOHibernate<Privilege> implements IPrivilegeDAO{

	@Override
	public Integer getPrivilegeCount() {
		String hql = "select count(privilege.id) from Privilege privilege";
		Long count = (Long) findUnique(hql);
		return MyStringUtils.translateLongToInteger(count);
	}
	
	@Override
	public List<Privilege> getPrivilegeList(Page page) {
		if (page != null) {
			return createQuery("from Privilege pri where pri.menu.target!=0").setFirstResult(page.getStartRow()).setMaxResults(page.getStartRow() + page.getPageSize()).list();
		} else {
			return createQuery("from Privilege pri where pri.menu.target!=0").list();
		}
	}
}
